package com.briup.cms.service.impl;

import com.briup.cms.bean.Carousel;
import com.briup.cms.dao.CarouselMapper;
import com.briup.cms.dao.extend.CarouselExtendMapper;
import com.briup.cms.exception.CustomerException;
import com.briup.cms.service.ICarouselService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Layla
 * @version 1.0
 * @date 2021/7/18 15:15
 */
@Service
public class CarouselServiceImpl implements ICarouselService {
    @Autowired
    private CarouselMapper carouselMapper;
    @Autowired
    private  CarouselExtendMapper carouselExtendMapper;
    @Override
    public PageInfo<Carousel> findAll(int pageNum, int pageSize) throws CustomerException {
        //1.设置分页信息
        PageHelper.startPage(pageNum,pageSize);
        List<Carousel> list = carouselExtendMapper.findAll();
        PageInfo<Carousel> pageInfo = new PageInfo<>(list);
        return  pageInfo;
    }
   //删除轮播页
    @Override
    public void deleteById(int id) throws CustomerException {
        carouselMapper.deleteByPrimaryKey(id);

    }


    //添加轮番页信息
    @Override
    public void saveCarousel(Carousel carousel) throws CustomerException {

        carouselMapper.insert(carousel);
    }
//更新轮播页信息
    @Override
    public void updateCarousel(Carousel carousel) throws CustomerException {
          carouselMapper.updateByPrimaryKey(carousel);
    }
//查询启用的轮播页
    @Override
    public List<Carousel> findYesCarousel() throws CustomerException {
        List<Carousel> list = carouselExtendMapper.selectByStatus(1);
        if(list ==null){
            list =new ArrayList<>();
        }
        return (List) list;
    }
}
